//index.js
//获取应用实例
const app = getApp()

Page({
  data: {

  },

  onLoad: function () {
    var that = this;
    wx.setNavigationBarTitle({
      title: "点点天气",
    })
    wx.request({
      url:app.globalData.targetUrl + "search/weather/",
      method:"GET",
      success:function(res){
        console.log(res);
        var weather = res.data.data.data.forecast;
        var ji = 12;
        for(var i = 0; i < weather.length; i++){
          while(weather[i].fengli[ji] != "级"){
            ji++;
          }
          weather[i].fengli = weather[i].fengli.slice(8,ji+2);
          ji=12;
        }
         var today = weather[0];
        var imagetype = "sunny";
        var str = today.type;
        var weathercolor = "#ff9b3f";
        if(today.type == "晴"){
          imagetype="sunny";
        }
        if(today.type == "多云"){
          imagetype="yin";
          weathercolor="#aaaaaa";
        }
        if(str.indexOf("雨") != -1){
          imagetype = "yu";
          weathercolor="#1296db";
        }
        if(str.indexOf("雪") != -1){
          imagetype = "xue";
          weathercolor="#7dc5eb";
        }
        that.setData({
          weather:weather,
          wendu:res.data.data.data.wendu,
          imagetype:imagetype,
          weathercolor:weathercolor
        })
      }
    })
  }
})
